package com.neuedu.oasystem.service.impl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.neuedu.oasystem.dao.IMeetingPlaceDao;
import com.neuedu.oasystem.dao.impl.MeetingPlaceDaoImpl;
import com.neuedu.oasystem.entity.MeetingPlace;
import com.neuedu.oasystem.service.MeetingPlaceService;
import com.neuedu.oasystem.util.DBHelper;
/**
 * MeetingPlace表实现
 * 	增（添加会议地点信息）
 * 	删（根据会议地址删除）
 * 	改（根据会议地点修改信息）
 * 	查（查询会议地址表所有信息）
 * @author admin
 *
 */
public class MeetingPlaceServiceImpl implements MeetingPlaceService{
	IMeetingPlaceDao meetingPlaceDao;
	public MeetingPlaceServiceImpl(){
		this.meetingPlaceDao = new MeetingPlaceDaoImpl();
	}
	/**
	 * 	添加会议地点信息
	 */
	@Override
	public boolean add(MeetingPlace param) {
		Connection connection = DBHelper.openConnection();
		try {
			meetingPlaceDao.setConnection(connection);
			connection.setAutoCommit(false);
			boolean bool = meetingPlaceDao.add(param);
			connection.commit();
			connection.setAutoCommit(false);
			return bool;
		} catch (SQLException e) {
			 //e.printStackTrace();
			if (connection != null) {
				try {
					connection.rollback();
					connection.setAutoCommit(true);
				} catch (SQLException e1) {
					 //e1.printStackTrace();
				}

			}
		}catch (RuntimeException e) {
			//e.printStackTrace();
		}finally {
			DBHelper.closeAll(null, null, connection);
		}
		return false;
	}

	/**
	 * 	根据会议地点修改信息
	 */
	@Override
	public boolean edit(MeetingPlace param) {
		Connection connection = null;
		connection = DBHelper.openConnection();
		meetingPlaceDao.setConnection(connection);
		try {
			connection.setAutoCommit(false);
			boolean bool = meetingPlaceDao.edit(param);
			connection.commit();
			connection.setAutoCommit(true);
			return bool;
		} catch (SQLException e) {
			 //e.printStackTrace();
			if (connection != null) {

				try {
					connection.rollback();
					connection.setAutoCommit(true);
				} catch (SQLException e1) {
					//e1.printStackTrace();
				}
			}
		}catch (RuntimeException e) {
			//e.printStackTrace();
		} finally {
			DBHelper.closeAll(null, null, connection);
		}
		return false;
	}

	@Override
	public boolean deleteById(int id) {
		Connection connection = null;
		connection = DBHelper.openConnection();
		meetingPlaceDao.setConnection(connection);
		try {
			connection.setAutoCommit(false);
			boolean bool = meetingPlaceDao.deleteById(id);
			connection.commit();
			connection.setAutoCommit(true);
			return bool;
		} catch (SQLException e) {
			//e.printStackTrace();
			if (connection!=null) {
				try {
					connection.rollback();
					connection.setAutoCommit(true);
				} catch (SQLException e1) {
					//e1.printStackTrace();
				}
			}
		}catch (RuntimeException e) {
			//e.printStackTrace();
		}finally {
			DBHelper.closeAll(null, null, connection);
		}
		return false;
	}

	@Override
	public MeetingPlace findById(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 	查询会议地址表所有信息
	 */
	@Override
	public List<MeetingPlace> findAll() {
		Connection connection = null;
		connection = DBHelper.openConnection();
		List<MeetingPlace> list = new ArrayList<MeetingPlace>();
		meetingPlaceDao.setConnection(connection);
		try {
		list =meetingPlaceDao.findAll();
		}catch (RuntimeException e) {
			//e.printStackTrace();
		}finally {
			DBHelper.closeAll(null, null, connection);
		}
		return list;
	}

	@Override
	public List<MeetingPlace> findByExample(MeetingPlace param) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<MeetingPlace> findByPager(int page, int size) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int deleteByIds(int[] ids) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int addAll(List<MeetingPlace> useparamrs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int editAll(List<MeetingPlace> param) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * 	根据会议地址删除
	 */
	@Override
	public boolean delete(MeetingPlace param) {
		Connection connection = DBHelper.openConnection();
		meetingPlaceDao.setConnection(connection);
		try {
			connection.setAutoCommit(false);
			boolean bool = meetingPlaceDao.delete(param);
			connection.commit();
			connection.setAutoCommit(true);
			return bool;
		} catch (SQLException e) {
			//e.printStackTrace();
			if (connection!=null) {
				try {
					connection.rollback();
					connection.setAutoCommit(true);
				} catch (SQLException e1) {
					//e1.printStackTrace();
				}
			}
		}catch (RuntimeException e) {
			//e.printStackTrace();
		}finally {
			DBHelper.closeAll(null, null, connection);
		}
		
		return false;
	}

}
